home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu745.dms / pu745.adf / GLOBE099.LHA / Ami-Globe / DATABASE.C < prev    next >
C/C++ Source or Header  |  1994-11-17  |  22KB  |  782 lines

  1.  
  2. /****************************************************************/
  3. /*                                                              */
  4. /*     fichier      : database.c                                */
  5. /*     projet       : amiglobe                                  */
  6. /*     date création: 1994                                      */
  7. /*     commentaire  : gestion des données sur les pays          */
  8. /*     révision     : $VER: database.c 0.004 (15 Oct 1994)
  9. /*     copyright    : © 1994 Olivier Collard                    */
  10. /*     $HISTORY:                                                */
  11. /*                                                              */
  12. /*     15 Oct 1994 : 000.004 :  free tab_data enleve pour la liste MUI LV_classement
  13. /*     12 Oct 1994 : 000.003 :  Type_Donnee
  14. /*     12 Oct 1994 : 000.002 :  liste de classement des pays
  15. /*                     1994 : 0.01 : version initiale           */
  16. /*                                                              */
  17. /****************************************************************/
  18.  
  19.  
  20. #include <exec/types.h>
  21. #include <exec/memory.h>
  22. #include <libraries/dos.h>
  23. #include <stdio.h>
  24. #include <string.h>
  25. #include <stdlib.h>
  26. #include <fcntl.h>
  27. #include <ctype.h>
  28.  
  29. /* Prototypes */
  30. #include <clib/exec_protos.h>
  31. #include <clib/dos_protos.h>
  32. #include <clib/alib_protos.h>
  33. #include <clib/macros.h>
  34.  
  35. /* MUI */
  36. #include <libraries/mui.h>
  37.  
  38. #include "amiglobe_types.h"
  39. #include "database_types.h"
  40. #include "map_function_protos.h"
  41. #include "database_protos.h"
  42. #include "fichier.h"
  43. #include "amiglobe_interf.h"
  44. #include "map_divers.h"
  45.  
  46. extern  COUNTRY *tab_country;/* tableau renseigne ici */
  47. extern  int max_country;
  48. extern  struct  ObjApp  *My_App;
  49. extern  PREFERENCE Pref;
  50.  
  51. #define BUFFER_SIZE 200
  52. #define MAX_LIGNE   10  /* Nombre de lignes max du cmt sur le pays */
  53. #define MAX_DATA    50
  54. ONE_TAB_DATA    Tab_Data[MAX_DATA];
  55. int Max_Data=0;
  56. E_Type_Data Type_Donnee;
  57.  
  58. /*****************************************/
  59. /* Recherche d'un pays en fct de son nom */
  60. /*****************************************/
  61.  
  62. int 
  63. Dtb_Find_Country_Pos(char   *P_Name)
  64. {
  65.     int i;
  66.     int num_cty;
  67.  
  68.     num_cty=-1;
  69.     i=0;
  70.     while ((i<max_country)&&(num_cty==-1))
  71.     {
  72.         if(strcmp(tab_country[i].name,P_Name)==0)
  73.         {
  74.             num_cty=i;
  75.         }
  76.         else
  77.         {
  78.             i++;
  79.         }
  80.     }
  81.     if (num_cty!=-1)
  82.         return(num_cty);
  83.     else
  84.     {
  85.         i=0;
  86.         while ((i<max_country)&&(num_cty==-1))
  87.         {
  88.             int longueur1,longueur2;
  89.             longueur1=strlen(P_Name);
  90.             longueur2=strlen(tab_country[i].name);
  91.             if(strncmp(tab_country[i].name,P_Name,MIN(longueur1,longueur2))==0)
  92.             {
  93.                 num_cty=i;
  94.             }
  95.             else
  96.             {
  97.                 i++;
  98.             }
  99.         }
  100.         return num_cty;
  101.     }
  102. }
  103.  
  104.  
  105. /*****************************************/
  106. /* Recherche d'un pays en fct de son nom */
  107. /*****************************************/
  108.  
  109. COUNTRY *
  110. Dtb_Find_Country(char  *P_Name)
  111. {
  112.     int i;
  113.     int Flg_Found;
  114.     COUNTRY *Ctry_Tmp;
  115.  
  116.     Flg_Found=FALSE;
  117.     Ctry_Tmp=tab_country;
  118.     i=0;
  119.     while ((i<max_country)&&(Flg_Found==FALSE))
  120.     {
  121.  
  122.         if(strcmp(Ctry_Tmp->name,P_Name)==0)
  123.         {
  124.             Flg_Found=TRUE;
  125.         }
  126.         else
  127.         {
  128.             if(i>MAX_COUNTRY)
  129.             {
  130.                 /*printf("Erreur, nbre maximum de pays depasse!\n");*/
  131.             }
  132.             else
  133.             {           
  134.                 Ctry_Tmp++;
  135.                 i++;
  136.             }
  137.         }
  138.     }
  139.     if (Flg_Found == FALSE)
  140.     {
  141.         Ctry_Tmp = NULL;
  142.     }
  143.     return(Ctry_Tmp);
  144. }
  145.  
  146. BOOL    
  147. get_int_line(FILE *fp,int *p_int)
  148. /* retourne un entier d'après la lecture d'une ligne d'un fichier texte */
  149. {
  150.     BOOL    Flg_Cont;
  151.     char    Buffer_Temp[BUFFER_SIZE],*P_Buf;
  152.  
  153.     Flg_Cont=TRUE;
  154.  
  155.     P_Buf = fgets(Buffer_Temp,BUFFER_SIZE,fp);
  156.  
  157.     if (P_Buf==NULL)
  158.     {
  159.         Flg_Cont=FALSE;
  160.     }
  161.     else
  162.     {
  163.         *p_int=atoi(P_Buf);
  164.     }
  165.     return(Flg_Cont);
  166. }
  167.  
  168. /* Initialise tout les champs d'une structure ctry a des valeurs correctes */
  169.  
  170. void    
  171. Dtb_Init_Country(COUNTRY *In_Cty)
  172. {
  173.     static  char    *P_Dummy="Non Defini";
  174.  
  175.     In_Cty->name=P_Dummy;
  176.     In_Cty->population=0;
  177.     In_Cty->superficie=0;
  178.     In_Cty->PIB=0;
  179.     In_Cty->off_name=P_Dummy;
  180.     In_Cty->presentation=P_Dummy;
  181.     In_Cty->P_Elem_Rem=NULL;
  182.  
  183.     In_Cty->pnb1=0;
  184.     In_Cty->pnb2=0;
  185.     In_Cty->pnb3=0;
  186.  
  187. }
  188.  
  189.  
  190. /* Lit la base de donnees concernant un pays */
  191.  
  192. BOOL    
  193. read_one_cty(FILE   *fp)
  194. {
  195.     char    Buffer_Temp[BUFFER_SIZE];
  196.     char    Buf_Cmt[MAX_LIGNE][BUFFER_SIZE];
  197.     char    *P_Buf;
  198.     char    *P_Car;
  199.     BOOL    Flg_Cont;
  200.     int Etape,i,Ligne;
  201.     int Len,Len_Total;
  202. /*  ELEM_REM * element;*/
  203.     COUNTRY *P_Ctry;    /* Pointeur sur le pays courant     */
  204.     static COUNTRY  Dummy_Ctry; /* Utilise si on ne trouve pas le pays  */
  205.     
  206.     Flg_Cont=TRUE;
  207.     Etape=0;
  208.     while ((Flg_Cont==TRUE)&&(Etape<20))
  209.     {
  210.       switch (Etape)
  211.       {
  212.         case 0:
  213.  
  214.         /* Lecture du nom du pays  A SUPPRIMER */
  215.  
  216.         P_Buf = fgets(Buffer_Temp,BUFFER_SIZE,fp);
  217.         if(P_Buf!=NULL)
  218.         {
  219.             /* Acquisition du nom du pays dans P_Buf */     
  220.             P_Car=stpchr(P_Buf,'|'); /*P_Car pointe sur le premier |*/
  221.             if (P_Car!=NULL) 
  222.                 *P_Car=0; 
  223.             P_Car = stpchr(P_Buf,0x0a);
  224.             if (P_Car!=NULL)
  225.                 *P_Car=0; 
  226.             
  227.             P_Ctry = Dtb_Find_Country(P_Buf);
  228.             if(P_Ctry==NULL)
  229.             {
  230.                 /*printf("ERREUR:Pays %s non trouvé...\n",P_Buf);*/
  231.                 P_Ctry=&Dummy_Ctry;
  232.                 Dtb_Init_Country(P_Ctry);
  233.             };
  234.         }
  235.         else
  236.         {
  237.             Flg_Cont=FALSE;
  238.         }
  239.         break;
  240.  
  241.         case 1:
  242.  
  243.         /* Lecture du nom officiel */
  244.         P_Buf = fgets(Buffer_Temp,BUFFER_SIZE,fp);
  245.         if(P_Buf==NULL)
  246.         {
  247.             Flg_Cont=FALSE;
  248.         }
  249.         else
  250.         {
  251.             /* Suppression du retour chariot */
  252.             Len=strlen(P_Buf);
  253.             P_Buf[Len-1]=0;
  254.             P_Ctry->off_name=malloc(Len);
  255.             strcpy(P_Ctry->off_name,P_Buf);
  256.         }
  257.         break;
  258.  
  259.          case 2:
  260.         /* Lecture de la surface */
  261.         Flg_Cont=get_int_line(fp,&P_Ctry->superficie);
  262.         break;
  263.  
  264.          case 3:
  265.         /* Lecture du nombre d'habitant */
  266.         Flg_Cont=get_int_line(fp,&P_Ctry->population);
  267.         break;
  268.  
  269.          case 4:
  270.         /* Lecture du PIB */
  271.         Flg_Cont=get_int_line(fp,&P_Ctry->PIB);
  272.         break;
  273.         
  274.          case 5:
  275.         {
  276.         ELEM_REM ** P_P_element=&(P_Ctry->P_Elem_Rem);
  277.         P_Buf = fgets(Buffer_Temp,BUFFER_SIZE,fp);
  278.         P_Ctry->P_Elem_Rem=NULL;
  279.         while ((P_Buf[0]!='&') && (P_Buf!=NULL))
  280.         {
  281.             ELEM_REM * nouvel_element=(ELEM_REM *)malloc(sizeof(ELEM_REM));
  282.             switch (atoi(strtok(P_Buf,"$")))
  283.             {
  284.                 case 0:nouvel_element->Type=CAPITALE;
  285.                     break;
  286.                 case 1:nouvel_element->Type=VILLE;
  287.                     break;
  288.                 case 2:nouvel_element->Type=MONUMENT;
  289.                     break;
  290.                 case 3:nouvel_element->Type=MONTAGNE;
  291.                     break;
  292.             }   
  293.             nouvel_element->Nom=strdup(strtok(NULL,"$"));
  294.             nouvel_element->Lat=-atoi(strtok(NULL,"$"));
  295.             nouvel_element->Lon=atoi(strtok(NULL,"$"));
  296.             nouvel_element->caracteristique=atoi(strtok(NULL,"$"));
  297.             *P_P_element=nouvel_element;
  298.             nouvel_element->P_Next=NULL;
  299.             P_P_element=&(nouvel_element->P_Next);
  300.             P_Buf = fgets(Buffer_Temp,BUFFER_SIZE,fp);
  301. /*          printf("Element remarquable pour %s : %s lon:%d lat:%d carac:%d\n",
  302.                 P_Ctry->name,(P_Ctry->P_Elem_Rem)->Nom,
  303.                 (P_Ctry->P_Elem_Rem)->Lon,(P_Ctry->P_Elem_Rem)->Lat,
  304.                 (P_Ctry->P_Elem_Rem)->caracteristique);*/
  305.         }   
  306.         }
  307.         break;
  308.  
  309.          case 6:
  310.         Ligne=0;
  311.         Len_Total=0;
  312.         do
  313.         {
  314.             P_Buf=fgets(&Buf_Cmt[Ligne][0],BUFFER_SIZE,fp);
  315.             if (P_Buf==NULL)
  316.             {
  317.                 Flg_Cont=FALSE;
  318.             };
  319.             Ligne++;
  320.             Len=strlen(P_Buf);
  321.             Len_Total+=Len;
  322.         }
  323.           while ((Ligne<MAX_LIGNE) && Flg_Cont && (P_Buf[Len-2]!='#') );
  324.  
  325.         if (Flg_Cont)
  326.         {
  327.             P_Ctry->presentation=(char *)malloc(Len_Total);
  328.             if (P_Ctry->presentation!=NULL)
  329.             {
  330.                 P_Ctry->presentation[0]=0;
  331.                 for(i=0;i<Ligne;i++)
  332.                 {
  333.                     strcat(P_Ctry->presentation,Buf_Cmt[i]);
  334.                 }
  335.                 P_Ctry->presentation[Len_Total-2]='\n';
  336.                 P_Ctry->presentation[Len_Total-1]=0;
  337.             }
  338.         }
  339.                 
  340.         break;
  341.  
  342.         case 7:
  343.  
  344.  
  345. /*      P_Ctry->pnb1=0;
  346.         P_Ctry->pnb2=0;
  347.         P_Ctry->pnb3=0;*/
  348.  
  349.  
  350.         /* Lecture du dernier retour chariot */
  351.         P_Buf = fgets(Buffer_Temp,BUFFER_SIZE,fp);
  352.         break;
  353.          default:
  354.         break;
  355.        }/* End of case */
  356.        Etape++;
  357.     }
  358.     return(Flg_Cont);
  359. }
  360.  
  361.  
  362. /* Lit la base de donnees concernant un pays */
  363.  
  364. BOOL    
  365. read_database(char *p_name)
  366. {
  367.     char    Buffer_Temp[BUFFER_SIZE];
  368.     BOOL    Flg_Cont;
  369.     FILE    *fp;
  370.     BOOL    Flg_Err=FALSE;
  371.     int i;
  372.     sprintf(Buffer_Temp,"%s.cty",p_name);
  373.     fp=fopen(Buffer_Temp,"r");
  374.     if (fp!=NULL)
  375.     {
  376.         Flg_Cont=TRUE;
  377.         while(Flg_Cont==TRUE)
  378.         {
  379.             Flg_Cont=read_one_cty(fp);
  380.         }
  381.         fclose(fp);
  382. /*        Dtb_Read_Data_File("stats/population_1993.stat");
  383.         if (Max_Data>0)
  384.             for (i=0;i<max_country;i++)
  385.                 tab_country[i].population=
  386.                     (int)(((int *)Tab_Data[Max_Data-1].P_Tab)[i]);
  387.  
  388.         Dtb_Read_Data_File("stats/superficie.stat");
  389.         if (Max_Data>1)
  390.             for (i=0;i<max_country;i++)
  391.                 tab_country[i].superficie=
  392.                     (float)(((float *)Tab_Data[Max_Data-1].P_Tab)[i]);*/
  393.     }
  394.     else
  395.     {
  396.         printf("ERROR: Cannot open the file:%s!\n",p_name);
  397.         Flg_Err=TRUE;
  398.     }
  399.     return Flg_Err;
  400. }
  401.  
  402. /* Lecture d'un fichier de donnees externe pour un pays */
  403. BOOL    
  404. Dtb_Read_Data_File(char *FileName)
  405. {
  406.     char    Buffer_Temp[BUFFER_SIZE];
  407.     char    P_Name[BUFFER_SIZE];
  408.     char    *P_Buf,*P_Car;
  409.     long int *P_Tab;
  410.     BOOL    Flg_Cont;
  411.     FILE    *fp;
  412.     int len;
  413.     int Num;
  414.     //int Val;
  415.     int Num_Data;
  416.     BOOL    Flg_Err=TRUE;
  417.  
  418.     if(fp=fopen(FileName,"r"))
  419.     {
  420.         Flg_Cont=FALSE;
  421.  
  422.         P_Buf = fgets(Buffer_Temp,BUFFER_SIZE,fp);
  423.         if (P_Buf!=NULL)
  424.         {
  425.             if (Max_Data<MAX_DATA)
  426.             {
  427.                 /* Préparation de la nouvelle donnée            */
  428.                 /* détection du type, initialisation du tableau */
  429.                 /* Rappel: format de la première ligne:         */
  430.                 /*  I Population                                */
  431.                 Num_Data=Max_Data;
  432.                 P_Tab=malloc(4*max_country);
  433.                 Tab_Data[Num_Data].P_Tab=P_Tab;
  434.                 if (P_Tab!=NULL)
  435.                 {
  436.                     int i=1;
  437.                     Max_Data++;
  438.                     Tab_Data[Num_Data].P_FileName=strdup(FileName);
  439.                     while ( P_Buf[i]==' ')
  440.                         i++;
  441.                     Tab_Data[Num_Data].Name=strdup(&P_Buf[i]);
  442.                         Tab_Data[Num_Data].Facteur=1.0;                 
  443.                     for (i=0;i<max_country;i++)
  444.                         P_Tab[i]=-~1;
  445.                     switch (P_Buf[0])
  446.                     {
  447.                     case 'I':
  448.  
  449.                         Tab_Data[Num_Data].SizeOf_Elem=sizeof(long int);
  450.                         Tab_Data[Num_Data].Type=DATA_INTEGER;
  451.  
  452.                         break;
  453.                     case 'F':
  454.                         Tab_Data[Num_Data].SizeOf_Elem=sizeof(float);
  455.                         Tab_Data[Num_Data].Type=DATA_FLOAT;
  456.  
  457.                         break;
  458.                     case 'C':
  459.                     
  460.  
  461.                         break;
  462.                     case 'P':
  463.                         Tab_Data[Num_Data].SizeOf_Elem=sizeof(float);
  464.                         Tab_Data[Num_Data].Type=DATA_PERCENT;
  465.  
  466.                         break;
  467.                     default:
  468.                         printf("%s: unknown data type\n",FileName);
  469.                         Flg_Cont=FALSE;
  470.                     }
  471.                 Flg_Cont=TRUE;
  472.                 }
  473.             }
  474.             else
  475.             {
  476.                 /*printf("Erreur. Nb maximum de fichiers externe atteint!\n");*/
  477.             }
  478.         }
  479.         while ((Flg_Cont==TRUE))
  480.         {
  481.             /* lecture de toutes les lignes du fichier */
  482.             P_Buf = fgets(Buffer_Temp,BUFFER_SIZE,fp);
  483.             if(P_Buf!=NULL)
  484.             {
  485.                 P_Car = strchr(P_Buf,':');
  486.                 if (P_Car == NULL)
  487.                     break;
  488.                 len=P_Car-P_Buf;
  489.                 while (P_Buf[len-1]==' ')
  490.                     len--;
  491.                 strncpy(P_Name,P_Buf,len);
  492.                 P_Name[len]=0;
  493.                 Num=Dtb_Find_Country_Pos(P_Name);
  494.                 if(Num!=-1)
  495.                 {
  496.                     char * pos;
  497.                     switch ( Tab_Data[Num_Data].Type)
  498.                     {
  499.  
  500.                     case DATA_INTEGER:
  501.                         P_Tab[Num]=(long int)atoi(&P_Car[1]);
  502.                         break;
  503.                     case DATA_FLOAT:
  504.                         {
  505.                             float val=atof(&P_Car[1]);
  506.                             memmove(&P_Tab[Num],&val,4);
  507.                         }
  508.                         break;
  509.                     case DATA_CHAR:
  510.                         break;
  511.                     case DATA_PERCENT:
  512.                         {
  513.                             float val;
  514.                         pos=strchr(&P_Car[1],'%');
  515.                         if (pos!=NULL)
  516.                             pos[0]=0;/* on efface le caractère '%' */
  517.                         val=atof(&P_Car[1]);
  518.                         memmove(&P_Tab[Num],&val,4);/* bourrin, non?*/
  519.                         /*val=0;
  520.                         memmove(&val,&P_Tab[Num],4);*/
  521.                         }
  522.                         break;
  523.                     default:
  524.                         break;
  525.                     }
  526.                 }
  527.                 Flg_Err=FALSE;
  528.             }
  529.             else
  530.             {
  531.                 Flg_Cont=FALSE;
  532.             }
  533.         }
  534.         fclose(fp);
  535.     } /*fin de si ouverture fichier*/
  536.     return(Flg_Err);
  537. }
  538.  
  539. /*****************************************************************************/
  540.  
  541. /* Fonction de comparaison pour le type entier */
  542.  
  543. int 
  544. cmp_int(DATA_TRI *data1,DATA_TRI *data2)
  545. {
  546.     if (data1->valeur.data_int<data2->valeur.data_int)
  547.         return 1;
  548.     else 
  549.     if(data1->valeur.data_int>data2->valeur.data_int)
  550.         return -1;
  551.     else
  552.         return 0;
  553. }
  554.  
  555. /* Fonction de comparaison pour le type flottant */
  556.  
  557. int 
  558. cmp_float(DATA_TRI *data1,DATA_TRI *data2)
  559. {
  560.     if (data1->valeur.data_float<data2->valeur.data_float)
  561.         return 1;
  562.     else 
  563.     if (data1->valeur.data_float>data2->valeur.data_float)
  564.         return -1;
  565.     return 0;
  566. }
  567.  
  568. /*****************************************************************************/
  569.  
  570. void 
  571. Dtb_Aff_Result(struct RastPort *rpG,int In_Num,APTR Liste_Sel,E_Type_Graph In_Type_Graph)
  572. {
  573.     int  i,nb_data;
  574.     int      nb_plages;     /* Nombre de plages */
  575.     long int   valeur_max;
  576.     COUNTRY  *P_Cty;
  577.     DATA_TRI *tab_data;
  578.     E_Type_Data type_data;
  579.     int *P_Tab_int,num;
  580.     float *P_Tab_float;
  581.         
  582. /*  LONG id = -1;*/
  583.     COUNTRY * pays;
  584.  
  585.     /* Recopie de la selection courante */
  586.     /* Temporaire               */
  587.     tab_data=(DATA_TRI *)malloc(sizeof(DATA_TRI)*max_country);
  588.     if (tab_data==NULL)
  589.         return;
  590.     Type_Donnee=Tab_Data[In_Num].Type;
  591.     P_Cty=tab_country;
  592.     switch (Tab_Data[In_Num].Type)
  593.     {
  594.     case DATA_INTEGER:
  595.         P_Tab_int=(int *)Tab_Data[In_Num].P_Tab;
  596.         break;
  597.     case DATA_FLOAT:
  598.         P_Tab_float=(float *)Tab_Data[In_Num].P_Tab;
  599.         break;
  600.     case DATA_PERCENT:
  601.         P_Tab_float=(float *)Tab_Data[In_Num].P_Tab;
  602.         break;      
  603.     }
  604.     /* création du tableau des données reliées à leur pays*/
  605.     for (nb_data=0;;nb_data++)
  606.     {
  607.  
  608.         DoMethod(Liste_Sel,MUIM_List_GetEntry,nb_data,&pays);
  609.         if (!pays) break;
  610.  
  611.         num=Dtb_Find_Country_Pos(pays->name);
  612.         
  613.         if(num!=-1)
  614.         {
  615.             switch (Tab_Data[In_Num].Type)
  616.             {
  617.             case DATA_INTEGER:
  618.                 tab_data[nb_data].valeur.data_int=P_Tab_int[num];
  619.                 break;
  620.             case DATA_FLOAT:
  621.             case DATA_PERCENT:
  622.                 tab_data[nb_data].valeur.data_float=P_Tab_float[num];
  623.                 break;      
  624.             }
  625.         }
  626.         else
  627.         {
  628.             switch (Tab_Data[In_Num].Type)
  629.             {
  630.             case DATA_INTEGER:
  631.                 tab_data[nb_data].valeur.data_int=-~1;
  632.                 break;
  633.             case DATA_FLOAT:
  634.             case DATA_PERCENT:
  635.                 tab_data[nb_data].valeur.data_int=-~1;
  636.                 break;      
  637.             }
  638.         }
  639.         tab_data[nb_data].Num_Pays=num;
  640.     }
  641.     /*printf("nb_data:%d\n",nb_data);*/
  642.  
  643.  
  644.     /* tri des donnees*/
  645.     switch(Tab_Data[In_Num].Type)
  646.     {
  647.         case DATA_INTEGER:
  648.            qsort( (void *)tab_data, nb_data , sizeof(DATA_TRI) , cmp_int );
  649.             valeur_max=tab_data[0].valeur.data_int;         
  650.             /*printf("valeur max:%d\n",valeur_max);*/
  651.             break;
  652.         case DATA_PERCENT:
  653.         case DATA_FLOAT:
  654.            qsort( (void *)tab_data, nb_data , sizeof(DATA_TRI) ,cmp_float);
  655.             valeur_max=tab_data[0].valeur.data_float;
  656.             /*valeur_max=tab_data[0].valeur.data_float;*/
  657.             /*printf("valeur_max:%d\n",valeur_max);*/
  658.             break;      
  659.         default:
  660.             break;
  661.     }
  662.  
  663.     nb_plages=Map_Get_Plages(rpG , 10 , type_data , nb_data ,0,100,In_Type_Graph);
  664.     //Map_Init_Graph(rpG,Tab_Data[In_Num].Name);
  665.     /* Pour tout les elements de la sélection, on va afficher les données   */
  666.     /* en fonction du nombre de plages                  */
  667.  
  668.     if(valeur_max!=0)
  669.     {
  670.         if (In_Type_Graph==0)
  671.         {
  672.             int rang=0;/* rang des pays */
  673.             int selectionne=-1;/* si un pays est sélectionné*/
  674.             set(My_App->LV_classement,MUIA_List_Quiet,TRUE);
  675.             set(My_App->TX_classement,MUIA_Text_Contents,
  676.                 Tab_Data[In_Num].Name);
  677.             /* données seules */
  678.             DoMethod(My_App->LV_classement,MUIM_List_Clear);
  679.             for(i=0;i<nb_data;i++)
  680.             {
  681.                 /* les valeurs égales à -~1 ne sont pas prises en compte*/
  682.                 if(tab_data[i].valeur.data_int!=-~1)
  683.                 {
  684.                     rang++;
  685.                     tab_data[i].Rang=rang;/* le rang commence à 1 */
  686.                     if (tab_data[i].Num_Pays==Pref.country_sel)
  687.                         selectionne=i;
  688.                     /* fonction de MUI 2.0 */
  689.                     DoMethod(My_App->LV_classement,MUIM_List_InsertSingle,
  690.                         &tab_data[i],MUIV_List_Insert_Bottom);
  691.                 }
  692.             }
  693.             if (selectionne!=-1)
  694.             {
  695.                 DoMethod(My_App->LV_classement,MUIM_List_Jump,selectionne);
  696.                 DoMethod(My_App->LV_classement,MUIM_List_Select,selectionne,
  697.                     MUIV_List_Select_On,NULL);
  698.             }
  699.             set(My_App->LV_classement,MUIA_List_Quiet,FALSE);
  700.             set(My_App->WI_Classement,MUIA_Window_Open,TRUE);
  701.         }
  702.         else
  703.         {
  704.            int rang=0;
  705.            /*valeur_max=valeur_max/nb_plages;*/
  706.            for(i=0;i<nb_data;i++)
  707.            {
  708.             if(tab_data[i].valeur.data_int!=-~1)
  709.             {
  710.                 rang++;
  711.                 tab_data[i].Rang=rang;
  712.             }
  713.            }
  714.            switch (In_Type_Graph)
  715.            {
  716.            case GRAPH_COL:
  717.                 aff_donnees(rpG,tab_data,valeur_max,type_data,nb_plages,nb_data);
  718.                 break;
  719.            default:
  720.                 break;
  721.  
  722.            }
  723.                     /*&tab_data[i],
  724.                     (int)((tab_data[i].valeur.data_int)/valeur_max)
  725.                     );*/
  726.  
  727.  
  728.         }
  729.     }
  730.     if (valeur_max==0 || In_Type_Graph!=0)
  731.         free(tab_data);
  732.     Map_End_Graph(rpG);
  733. }
  734. /***********************************************************************/
  735. void
  736. Dtb_Create_Liste_Data(APTR List)
  737. {
  738.     int i;
  739.     
  740. /*    for(i=0;i<Max_Data;i++){
  741.         DoMethod(List,
  742.             MUIM_List_Remove,MUIV_List_Remove_First);
  743.     
  744.     }*/
  745.     DoMethod(List,MUIM_List_Clear);
  746.     for (i=0;i<Max_Data;i++)
  747.     {
  748.         DoMethod(List,
  749.             MUIM_List_Insert,&Tab_Data[i].Name,1,
  750.             MUIV_List_Insert_Bottom);
  751.     }
  752. }
  753.  
  754. /***********************************************************************/
  755. BOOL    
  756. Dtb_Read_Stats(void)
  757. {
  758.     static BOOL Initialise=FALSE;
  759.     /* si on ne trouve aucun fichier de stat, on continue quand même*/
  760.     BOOL    Flg_Err=FALSE;
  761.     if (Initialise==FALSE)
  762.     {
  763.         char * nom_fichier=ouvrir_nouveau_fichier("Stats/#?.stat");
  764.         while (nom_fichier!=NULL)
  765.         {
  766.             char buffer[256];
  767.             strcpy(buffer,"stats/");
  768.             /*Flg_Err=Dtb_Read_Data_File(buffer);
  769.             Flg_Err=Dtb_Read_Data_File("stats/chomage.stat");
  770.             Flg_Err=Dtb_Read_Data_File("stats/death_rate.stat");
  771.             Flg_Err=Dtb_Read_Data_File("stats/superficie.stat");
  772.             Flg_Err=Dtb_Read_Data_File("stats/land_boundaries.stat");*/
  773.             Flg_Err=Dtb_Read_Data_File(strcat(buffer,nom_fichier));
  774.             nom_fichier=ouvrir_nouveau_fichier("Stats/#?.stat");
  775.         }
  776.         Dtb_Create_Liste_Data(My_App->LV_Datas);
  777.         Initialise=TRUE;
  778.     }
  779.     return(Flg_Err);
  780. }
  781.  
  782.